
package com.idealighter.game.games.weishuwu.struct;

import com.idealighter.game.core.common.Game;
import com.idealighter.game.dictionary.domain.WeishuwuRoomDomain;
import com.idealighter.game.games.common.AbstractRoom;
import com.idealighter.game.games.common.AbstractSeat;
import com.idealighter.game.games.common.AbstractTable;
import com.idealighter.game.games.weishuwu.manager.WeishuwuDataMgr;
import com.idealighter.game.server.context.ApplicationContext;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 魏蜀吴房间 .
 */
public class WeishuwuRoom extends AbstractRoom {

  // 桌子
  public final Map<Integer, WeishuwuTable> tables;

  /**
   * 构造函数.
   * 
   * @param roomDom .
   */
  public WeishuwuRoom(WeishuwuRoomDomain roomDom) {
    super(roomDom.getId(), roomDom.getName());
    this.tables = createTables(roomDom.getTable());
  }

  /**
   * 创建桌子 .
   * 
   * @param tableNum .
   * @return
   */
  private Map<Integer, WeishuwuTable> createTables(int tableNum) {
    Map<Integer, WeishuwuTable> tables = new LinkedHashMap<>();

    for (int i = 0; i < tableNum; i++) {
      int tableId = id.intValue() * AbstractTable.MAX_TABLE + i + 1;
      tables.put(tableId, new WeishuwuTable(tableId, this));
    }

    return tables;
  }

  @Override
  public Game game() {

    return Game.WEISHUWU;
  }

  @Override
  public AbstractSeat seat(long playerId) {

    return ApplicationContext.getBean(WeishuwuDataMgr.class).getPlayerSeat(playerId);
  }

  @Override
  public Collection<WeishuwuTable> tables() {

    return tables.values();
  }

}
